package com.demo.service.impl;

import com.demo.dao.DeviceMapper;
import com.demo.beans.Device;
import com.demo.beans.Page;
import com.demo.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class DeviceServiceImpl implements DeviceService {
    @Autowired
    private DeviceMapper deviceMapper;
    @Override
    public Page<Device> getDeviceList(int pageIndex, int pageSize, Long id) {
        int fromIndex = (pageIndex - 1) * pageSize;
        List<Device> deviceList = deviceMapper.getDeviceList(fromIndex, pageSize, id);
        int count = deviceMapper.getDeviceCount(id);
        Page<Device> page = new Page<>(pageIndex, pageSize, count, deviceList);
        return page;
    }

    @Override
    public int addDevice(Device device) {
        return deviceMapper.add(device);
    }

    @Override
    public int updateDevice(Long id) {
        return deviceMapper.updateDevice(id);
    }

    @Override
    public int updateDevice2(Long id) {
        return deviceMapper.updateDevice2(id);
    }


}
